home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / Developer Essentials Jul 90 / Technical Docs / Apple II Technical Notes / Technical Notes (Text) / IIGS / TN.IIGS.034 < prev    next >
Encoding:
Text File  |  1989-02-22  |  19.1 KB  |  431 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. Apple IIGS
  7. #34:    Low-Level QuickDraw II Routines
  8.  
  9. Revised by:    Keith Rollin, Steven Glass, Matt Deatherage
  10.                & Eric Soldan                                     January 1989
  11. Written by:    Steven Glass                                          May 1988
  12.  
  13. This Technical Note describes the low-level routines which QuickDraw II uses 
  14. to do much of the work in standard calls and mechanisms for calling these 
  15. routines and accessing their data.
  16. Changed since November 1988:  Expanded the section on "Dealing with the 
  17. Cursor" and documented a bug in ShieldCursor.
  18. _____________________________________________________________________________
  19.  
  20. QuickDraw II lets you customize low-level drawing operations by intercepting 
  21. the "bottleneck procedures."  QuickDraw II calls an appropriate "bottleneck 
  22. proc" every time it receives a call to draw an object, measure text, or deal 
  23. with pictures.  For example, if an application calls PaintOval, QuickDraw II 
  24. calls StdOval to do the real work, and if an application calls InvertRgn, 
  25. QuickDraw II calls StdRgn to do the work.
  26.  
  27. Installing your own bottleneck procedures is a little bit tricky.  The 
  28. QuickDraw II SetStdProcs call accepts a pointer to a 56-byte ($38 hex) record 
  29. and fills that record with the addresses of the standard bottleneck procedures 
  30. of QuickDraw II.  You may modify this record by replacing those addresses with 
  31. the addresses of your own custom bottleneck procedures minus one.  (QuickDraw 
  32. II pushes the address on the stack and executes an RTL to it, so the address 
  33. in the record must point to the byte before the routine.)  After installing 
  34. your own procedures, you use SetGrafProcs to tell QuickDraw II about them.  
  35. The format of this call is as follows (taken from the E16.QUICKDRAW file in 
  36. APW):
  37.  
  38.     ostdText      GEQU   $00 ; Pointer - QDProcs -  
  39.     ostdLine      GEQU   $04 ; Pointer - QDProcs -  
  40.     ostdRect      GEQU   $08 ; Pointer - QDProcs -  
  41.     ostdRRect     GEQU   $0C ; Pointer - QDProcs -  
  42.     ostdOval      GEQU   $10 ; Pointer - QDProcs -  
  43.     ostdArc       GEQU   $14 ; Pointer - QDProcs -  
  44.     ostdPoly      GEQU   $18 ; Pointer - QDProcs -  
  45.     ostdRgn       GEQU   $1C ; Pointer - QDProcs -  
  46.     ostdPixels    GEQU   $20 ; Pointer - QDProcs -  
  47.     ostdComment   GEQU   $24 ; Pointer - QDProcs -  
  48.     ostdTxMeas    GEQU   $28 ; Pointer - QDProcs -  
  49.     ostdTxBnds    GEQU   $2C ; Pointer - QDProcs -  
  50.     ostdGetPic    GEQU   $30 ; Pointer - QDProcs -  
  51.     ostdPutPic    GEQU   $34 ; Pointer - QDProcs -  
  52.  
  53. The following code fragment shows how you might replace the StdRect procedure 
  54. with your own for a given window:
  55.  
  56.     pha                            ; open a test window
  57.     pha
  58.     PushLong #MWindData            ; standard setup for NewWindow
  59.     _NewWindow
  60.     _SetPort
  61.     
  62.     PushLong #MyProcs              ; get a record to modify
  63.     _SetStdProcs
  64.     
  65.     ldy #ostdRect                  ; get the low word of my rectangle routine
  66.     lda #myRect-1                  ; (minus one) and patch it in to the record
  67.     sta myProcs,y
  68.     lda #^myRect                   ; do the same for the high word
  69.     sta myProcs+2,y
  70.     
  71.     PushLong #MyProcs              ; install the procs
  72.     _SetGrafProcs
  73.  
  74. The interface to bottleneck procedures is different from the interface to 
  75. other QuickDraw II routines; you do not make calls via the tool dispatcher and 
  76. you pass most parameters on the direct page and in registers (rather than on 
  77. the stack).  To write your own bottleneck procedures, you have to know where 
  78. the inputs to each call are kept and how to call the standard procedures from 
  79. inside your own procedures.  
  80.  
  81. The standard bottleneck procedures are accessed through vectors in bank $E0.
  82.  
  83.     StdText       $E01E04
  84.     StdLine       $E01E08
  85.     StdRect       $E01E0C
  86.     StdRRect      $E01E10
  87.     StdOval       $E01E14
  88.     StdArc        $E01E18
  89.     StdPoly       $E01E1C
  90.     StdRgn        $E01E20
  91.     StdPixels     $E01E24
  92.     StdComment    $E01E28
  93.     StdTxMeas     $E01E2C
  94.     StdTxBnds     $E01E30
  95.     StdGetPic     $E01E34
  96.     StdPutPic     $E01E38
  97.  
  98. When you call any of the standard procedures, the first direct page of 
  99. QuickDraw II is active.  If you pass variables on any direct page other than 
  100. the first (direct page locations greater than $FF), you can use a simple trick 
  101. to access them.  For example, to access TheFillPat ($10E) without changing the 
  102. direct page register:
  103.  
  104.     ldx    #$100                   ;offset to second DP
  105.     lda    >$OE,X                  ;gets "DP" location $10E
  106.  
  107. Certain locations on the direct page are always valid:
  108.  
  109.     PortRef      $24
  110.     MaxWidth     $20
  111.     MasterSCB    $08
  112.     UserID       $0A
  113.  
  114. DrawVerb is usually valid, but not always:
  115.  
  116.     DrawVerb     $38
  117.  
  118. Each of the bottleneck procedures uses the direct page differently.
  119.  
  120. QuickDraw II has an interesting bug relating to the standard conic bottleneck 
  121. procedures.  If you replace any of the standard procedures with your own, 
  122. QuickDraw II does not perform some of the setups it normally would before 
  123. calling the standard conic procedures (stdRRect, stdOval, stdArc).  For 
  124. example, if you replace StdRect with a custom rectangle routine, but leave the 
  125. other conic pointers alone (as shown in the code fragment above), QuickDraw II 
  126. will not do all of the normal setups when calling the standard conic routines.  
  127. To deal with this bug of QuickDraw II, you must patch out the additional 
  128. bottleneck procedures and set up those direct pages locations yourself, or the 
  129. results will not be what you expect.  The QuickDraw II direct-page variables 
  130. you must initialize yourself in this instance are bulleted (o) below.
  131.  
  132. StdText
  133.     DrawVerb      $38    Describes the kind of text to draw.  There 
  134.                          are three possible values:
  135.                              DrawCharVerb    0
  136.                              DrawTextVerb    1
  137.                              DrawCStrVerb    2
  138.     TextPtr       $DA    If the draw verb is DrawTextVerb or 
  139.                          DrawCStrVerb, TextPtr points to the text 
  140.                          buffer or C string to draw.
  141.     TextLength    $D8    If the draw verb is DrawTextVerb, 
  142.                          TextLength contains the number of bytes in 
  143.                          the text buffer.
  144.     CharToDraw    $D6    If the draw verb is DrawCharVerb, 
  145.                          CharToDraw contains the character to draw.
  146.  
  147. StdLine
  148.     Y1            $A6    Starting Y value for the line to draw
  149.     X1            $A8    Starting X value for the line to draw
  150.     Y2            $AA    Ending Y value for the line to draw
  151.     X2            $AB    Ending X value for the line to draw
  152.     Rect2         $AE    Exactly the same thing as Y1, X1, Y2 and 
  153.                          X2 in the top, left, bottom, and right of 
  154.                          the rectangle
  155.  
  156. StdRect
  157.     DrawVerb      $38    One of the following five drawing verbs:
  158.                              Frame           0
  159.                              Paint           1
  160.                              Erase           2
  161.                              Invert          3
  162.                              Fill            4
  163.     Rect1         $A6    The rectangle to draw in standard form 
  164.                          (top, left, bottom, right)
  165.     TheFillPat    $10E   The pattern to use for the rectangle if 
  166.                          the verb is Fill
  167.  
  168. Note:    The QuickDraw II Auxiliary SpecialRect call does not use the 
  169. rectangle bottleneck procedures.
  170.  
  171. StdRRect
  172.     DrawVerb      $38    One of the following five drawing verbs:
  173.                              Frame           0
  174.                              Paint           1
  175.                              Erase           2
  176.                              Invert          3
  177.                              Fill            4
  178.     Rect1         $A6    The boundary rectangle for the round 
  179.                          rectangle
  180.     OvalRect      $295   A copy of the boundary rectangle for the 
  181.                          round rectangle
  182.     OvalHeight    $208   The oval height for the rounded part of 
  183.                          the round rectangle
  184.     OvalWidth     $20A   The oval width for the rounded part of the 
  185.                          round rectangle
  186.     o ArcAngle    $D2    Must be 360
  187.     o StartAngle  $D4    Must be zero
  188.     TheFillPat    $10E   The pattern to use for the round rectangle 
  189.                          if the verb is Fill
  190.  
  191. StdOval
  192.     DrawVerb      $38    One of the following five drawing verbs:
  193.                              Frame           0
  194.                              Paint           1
  195.                              Erase           2
  196.                              Invert          3
  197.                              Fill            4
  198.     Rect1         $A6    The boundary rectangle for the oval
  199.     OvalRect      $295   A copy of the boundary rectangle for the 
  200.                          oval
  201.     o OvalHeight  $208   Must be the height of the oval
  202.     o OvalWidth   $20A   Must be the width of the oval
  203.     o ArcAngle    $D2    Must be 360
  204.     o StartAngle  $D4    Must be zero
  205.     TheFillPat    $10E   The pattern to use for the oval if the 
  206.                          verb is Fill
  207.  
  208. StdArc
  209.     DrawVerb      $38    One of the following five drawing verbs:
  210.                              Frame           0
  211.                              Paint           1
  212.                              Erase           2
  213.                              Invert          3
  214.                              Fill            4
  215.     Rect1         $A6    The boundary rectangle for the arc
  216.     o OvalWidth   $20A   Must be the width of the boundary 
  217.                          rectangle for the arc
  218.     ArcAngle      $D2    The number of degrees the arc will sweep
  219.     StartAngle    $D4    The starting position of the arc
  220.     TheFillPat    $10E   The pattern to use for the arc if the verb 
  221.                          is Fill
  222.  
  223. StdPoly
  224.     DrawVerb      $38    One of the following five drawing verbs:
  225.                              Frame           0
  226.                              Paint           1
  227.                              Erase           2
  228.                              Invert          3
  229.                              Fill            4
  230.     RgnHandleA    $50    The handle to the polygon data structure
  231.     TheFillPat    $10E   The pattern to use for the polygon if the 
  232.                          verb is Fill
  233.  
  234. StdRgn
  235.     DrawVerb      $38    One of the following five drawing verbs:
  236.                              Frame           0
  237.                              Paint           1
  238.                              Erase           2
  239.                              Invert          3
  240.                              Fill            4
  241.     RgnHandleC    $70    The handle to the region to draw
  242.     TheFillPat    $10E   The pattern to use for the region if the 
  243.                          verb is Fill
  244.  
  245. StdPixels
  246.     SrcLocInfo    $CC    The LocInfo record for the source pixel 
  247.                          map
  248.     DestLocInfo   $0C    The LocInfo record for the destination 
  249.                          pixel map
  250.     SrcRect       $DC    The source rectangle for the operation in 
  251.                          local coordinates for the source pixel map 
  252.                          (as described in the source LocInfo 
  253.                          record)
  254.     DestRect      $1C    The destination rectangle for the 
  255.                          operation in local coordinates for the 
  256.                          destination pixel map (as described in the 
  257.                          destination  LocInfo record)
  258.     XferMode      $E4    The mode to use for data transfer
  259.     RgnHandleA    $50    The handle to the first region to which 
  260.                          drawing is clipped (usually the ClipRgn 
  261.                          from the GrafPort)  A NIL handle is not 
  262.                          allowed.  To signify no clipping, pass a 
  263.                          handle to the WideOpen region, which is 
  264.                          defined as 10 bytes:
  265.  
  266.                          Length      $A       (word)
  267.                          -MaxInt    -$3FFF    (word)
  268.                          -MaxInt    -$3FFF    (word)
  269.                          +MaxInt    +$3FFF    (word)
  270.                          +MaxInt    +$3FFF    (word)
  271.  
  272.     RgnHandleB    $60    The handle to the second region to which 
  273.                          drawing is clipped (usually the VisRgn 
  274.                          from the GrafPort)  A NIL handle is not 
  275.                          allowed.  To signify no clipping, pass a 
  276.                          handle to the WideOpen region.
  277.     RgnHandleC    $70    The handle to the second region to which 
  278.                          drawing is clipped (usually the mask 
  279.                          region from the CopyPixels or the 
  280.                          PaintPixels call)  A NIL handle is not 
  281.                          allowed.  To signify no clipping, pass a 
  282.                          handle to the WideOpen region.
  283.  
  284. StdComment
  285.     TheKind       $A6    The kind of input for the comment
  286.     TheSize       $A8    The number of bytes to put into the 
  287.                          picture
  288.     TheHandle     $AA    The data to put into the picture
  289.  
  290. StdTxMeas
  291.     DrawVerb      $38    Describes the kind of text to draw.  There 
  292.                          are three possible values:
  293.                              DrawCharVerb    0
  294.                              DrawTextVerb    1
  295.                              DrawCStrVerb    2
  296.     TextPtr       $DA    If the draw verb is DrawTextVerb or 
  297.                          DrawCStrVerb, TextPtr points to the text 
  298.                          buffer or C string to draw.
  299.     TextLength    $D8    If the draw verb is DrawTextVerb, 
  300.                          TextLength contains the number of bytes in 
  301.                          the text buffer.
  302.     CharToDraw    $D6    If the draw verb is DrawCharVerb, 
  303.                          CharToDraw contains the character to 
  304.                          measure.
  305.     TheWidth      $DE    The resulting width should be put here.
  306.  
  307. StdTxBnds
  308.     DrawVerb      $38    Describes the kind of text to draw.  There 
  309.                          are three possible values:
  310.                              DrawCharVerb    0
  311.                              DrawTextVerb    1
  312.                              DrawCStrVerb    2
  313.     TextPtr       $DA    If the draw verb is DrawTextVerb or 
  314.                          DrawCStrVerb, TextPtr points to the text 
  315.                          buffer or C string to draw.
  316.     TextLength    $D8    If the draw verb is DrawTextVerb, 
  317.                          TextLength contains the number of bytes in 
  318.                          the text buffer.
  319.     CharToDraw    $D6    If the draw verb is DrawCharVerb, 
  320.                          CharToDraw contains the character to draw.
  321.     RectPtr       $D2    Indicates the address to put the resulting 
  322.                          rectangle.
  323.  
  324. StdGetPic
  325.     This call takes input on the stack rather than the direct page.  This is 
  326.     the one standard bottleneck procedure which you call with the direct 
  327.     page register set to something other than the direct page of QuickDraw 
  328.     II; it is set to a part of the stack.
  329.  
  330.     Stack Diagram on Entrance to StdGetPic
  331.         Previous Contents
  332.         DataPtr              Pointer to destination buffer
  333.         Count                Integer (unsigned) (bytes to read)
  334.         RTL Address          3 bytes
  335.         -----------------    Top of Stack
  336.  
  337.     Stack Diagram just before exit from StdGetPic
  338.         Previous Contents
  339.         RTL Address          3 bytes
  340.         -----------------    Top of Stack
  341.  
  342. StdPutPic
  343.     This call takes input on the stack rather than the direct page; however, 
  344.     unlike StdGetPic, the direct page for QuickDraw II is active when you 
  345.     call this routine.
  346.  
  347.     Stack Diagram on Entrance to StdPutPic
  348.  
  349.         Previous Contents
  350.         DataPtr              Pointer to source buffer
  351.         Count                Integer (unsigned) (bytes to read)
  352.         RTL Address          3 bytes
  353.         -----------------    Top of Stack
  354.  
  355.     Stack Diagram just before exit from StdPutPic
  356.  
  357.         Previous Contents
  358.         RTL Address          3 bytes
  359.         -----------------    Top of Stack
  360.  
  361.  
  362. Dealing with the Cursor
  363.  
  364. The cursor can get in your way when you want to draw directly to the screen.  
  365. QuickDraw II has two low-level routines which help you avoid this problem:  
  366. ShieldCursor and UnshieldCursor.  ShieldCursor tells QuickDraw II to hide the 
  367. cursor if it intersects the MinRect and to prevent the cursor from moving 
  368. until you call UnshieldCursor.
  369.  
  370. There is a bug in ShieldCursor for System Disks 4.0 and earlier.  This bug is 
  371. related to the routine ObscureCursor.  When the cursor is obscured, 
  372. ShieldCursor does not prevent the cursor from moving; therefore, the user is 
  373. able to move the cursor during a QuickDraw II operation, and this movement may 
  374. disturb the screen image.
  375.  
  376. Calls to ShieldCursor must be balanced by calls to UnshieldCursor.  You may 
  377. not call ShieldCursor successively without calling UnshieldCursor after each 
  378. call to ShieldCursor.  There is no error checking, so careless use of these 
  379. routines will result in an unusable system.
  380.  
  381. MinRect is the smallest possible rectangle which encloses all the pixels that 
  382. may be affected by a drawing call.  You keep MinRect on the direct page and 
  383. usually calculate it by intersecting the rectangle of the object you are 
  384. drawing with the BoundsRect, PortRect, boundary box of the VisRgn, and the 
  385. boundary box of the ClipRgn.  You must set up MinRect yourself.
  386.  
  387. ShieldCursor also looks at two other fields on the direct page of QuickDraw 
  388. II.  ImageRef is a long word located at $0E.  If ImageRef does not point to 
  389. $E12000, QuickDraw II assumes you are not drawing to the screen, so it does 
  390. not have to shield the cursor.  BoundsRect is a rectangle located at $14, and 
  391. QuickDraw II uses it to translate MinRect into global coordinates.  These 
  392. values are generally correct, but under the following known circumstance, they 
  393. are not and ShieldCursor will not function properly:
  394.  
  395. 1.    You have just drawn to an off-screen GrafPort with QuickDraw II.
  396. 2.    You switch to a GrafPort on the screen.
  397. 3.    You call ShieldCursor.
  398.  
  399. ImageRef and BoundsRect are not updated until QuickDraw II is actually 
  400. committed to drawing, thus, these values are still for the off-screen GrafPort 
  401. in this case, even though you switched to a GrafPort on the screen.  
  402. Therefore, when you call ShieldCursor, you have to make sure that these values 
  403. are current.  (If these values are current, ShieldCursor will work correctly, 
  404. no matter what the circumstances.)
  405.  
  406. You can find the location of the QuickDraw II direct page with the GetWAP 
  407. call.  For speed reasons, you may not want to make the GetWAP call for each 
  408. ShieldCursor call.  You may wish to get the work area pointer value after 
  409. starting QuickDraw II and store it for future reference.
  410.  
  411. Calling ShieldCursor:
  412. 1.    Set direct page for QuickDraw II.
  413. 2.    Set MinRect, ImageRef, and BoundsRect.
  414. 3.    Call ShieldCursor.
  415.  
  416. Calling UnshieldCursor:
  417. 1.    Set direct page for QuickDraw II.
  418. 2.    Call UnshieldCursor.
  419.  
  420. ShieldCursor      $E01E98
  421.     MinRect       $00
  422.     ImageRef      $0E
  423.     BoundsRect    $14
  424.  
  425. UnshieldCursor    $E01E9C
  426.  
  427.  
  428. Further Reference
  429. _____________________________________________________________________________
  430. o    Apple IIGS Toolbox Reference, Volume 2
  431.